﻿<?php
class Menu {
	
	//property
	protected $title;
	protected $href;
	protected $target;
	protected $menuList = array();
	
	//생성자
	public function __construct($title, $href, $target=""){
		$this->title = $title;
		$this->href = $href;
		$this->target = $target;
	}
	
	//접근 함수
	public function __get($name){
		return $title->$name;
	}
	
	//접근 함수
	public function __set($name, $value){
		$this->$name = $value;
	}
	
	//소멸자
	public function __destruct(){
	
	}
	
	public function addMenu($id, Menu $menu){
		$this->menuList[$id] = $menu;
	}
	
	public function removeMenu($id){
		unset($this->menuList[$id]);
	}
	
	public function display(){
		$text = "<li><a href='" . $this->href . "'";
		if (!$this->target){      //(!$this->target) = ($this->target !="")
			$text .= " target='" . $this->target . "'>";	
		} else {
			$text .= ">";
		}
		$text .= $this->title . "</a>";
		if (!empty($this->menuList)){       //(!empty(배열이름)) 이건 배열이 비었나 안 비었나를 확인해주는 것.
			$text .= "<ul>";
			foreach ($this->menuList as $single) {
				$text .= $single->display();
			}
			$text .= "</ul>";
		}
		$text .= "</li>";
		return $text;
	}
}
?>